<?php

declare (strict_types = 1);

namespace app\store\controller;

use app\store\service\Home as HomeService;
use think\facade\Cache;

/**
 * 后台首页
 * Class Home
 * @package app\store\controller
 */
class Home extends Controller
{
    /**
     * 后台首页
     * @return array
     */
    private static $home_data_key = 'store_home_data';
    private static $home_data_key_expire = 300;
    public function data()
    {
        // 获取首页数据
        $model = new HomeService;
        $home_data = Cache::store('redis')->get(self::$home_data_key);
        if($home_data){
            $data = json_decode($home_data,true);
        }else{
            $data =  $model->getData();
            Cache::store('redis')->set(self::$home_data_key,json_encode($data),self::$home_data_key_expire);
        }
        return $this->renderSuccess(compact('data'));
    }

}
